package homework;

import com.sun.xml.internal.ws.api.model.wsdl.WSDLOutput;

import java.util.Random;
import java.util.Scanner;

public class day06练习2 {
    public static void main(String[] args) {
        say();
        System.out.println("-----");
        say("haha");
        System.out.println("-----");
        say("heihei,45");
        System.out.println("-----");
        int b =sum(5,6);
        System.out.println(b);
        int m=5,n=6;
        int c=sum(m,n);
        System.out.println(c);
        int[] d = generateArray(5,10);
        System.out.println("数组长度为:"+d.length);
        for (int i =0;i<d.length;i++){
            System.out.println(d[i]);
        }
        int[] e = generateArray(10,50);
        System.out.println("第1个元素值:"+e[0]);
        for (int i=0;i<e.length;i++){
            System.out.println(e[i]);
        }
       double[] scores = inputData(6);
        double avg = calAvg(scores);
        System.out.println("平均分为:"+avg);

        Scanner scan = new Scanner(System.in);
        Random rand = new Random();
        int num =rand.nextInt(1000)+1;
        while (true){
            System.out.println("猜吧!");
            int guess = scan.nextInt();
            if(guess>num){
                System.out.println("猜大了");
            }else if (guess<num){
                System.out.println("猜小了");
            }else{
                System.out.println("恭喜你猜对了!");
                break;
            }
        }








    }










   //录入N位评委的分数
    public static double[] inputData(int n){
        double[] scores = new double[n];
        Scanner scan = new Scanner(System.in);
        for (int i=0;i<scores.length;i++){
            System.out.println("请录入第"+(i+1)+"个评委的分数");
            scores[i] = scan.nextDouble();
        }
        return scores;
    }
    //计算平均分数
    public static double calAvg(double[] scores){
        double total = 0.0;
        double max = scores[0];
        double min = scores[0];
        for (int i=0;i<scores.length;i++){
            total = total+scores[i];
            if (scores[i]>max){
                max= scores[i];
            }
            if (scores[i]<min){
                min = scores[i];
            }
        }
        double avg = (total-max-min)/(scores.length-2);
        return avg;
    }





    //定义generateArray()用于生成整型数组填充随机数并返回数组
    public static int[] generateArray (int len,int max){
        Random rand = new Random();
        int[] arr = new int[len];
        for (int i=0;i<arr.length;i++){
            arr[i] = rand.nextInt(max+1);
        }
        return arr;
    }
    //定义sum()两个参有返回值方法
    public static int sum(int num1,int num2){
        int num = num1+num2;
        return num;
    }
    //定义say()有两个参无返回值的方法
    public static void say(String name,int age){
        System.out.println("大家好,我叫"+name+",今年"+age+"岁了");
    }
    //定义say()有一个参无返回值方
    public static void say(String name){
        System.out.println("大家好,我叫"+name+",今年65岁了");
    }
    //定义say()无参无返回值方法
    public static void say(){
        System.out.println("大家好,我叫哈哈,今年20岁了");
    }

}
